﻿using System;

class SubstringInAGivenText
{
    static void Main()
    {
        //Exercise 4.
        //Write a program that finds how many times a substring is contained in a given text (perform case insensitive search).
        //Example: The target substring is "in". The text is as follows:
        //We are living in an yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are 
        //drinking all the day. We will move out of it in 5 days.
        //The result is: 9.

        //IF YOU'D LIKE, YOU MAY TYPE YOUR TEXT HERE:
        //Console.Write("Type the text: ");
        //string text = Console.ReadLine();
        //Console.Write("Type the keyword to be looked for: ");
        //string keyword = Console.ReadLine();

        string text = @"We are living in an yellow submarine. We don't have anything else. Inside the submarine is very tight. 
                        So we are drinking all the day. We will move out of it in 5 days.";
        string keyword = "in";
        int counter = 0;
        int index = text.ToLower().IndexOf(keyword.ToLower());

        for (int i = 0; i < text.Length; i++)
        {
            while (index != -1)
            {
                counter++;
                index = text.ToLower().IndexOf(keyword.ToLower(), index + 1);
            }
        }
        Console.WriteLine("The keyword \"{0}\" is found {1} times.", keyword, counter);

    }
}

